<template>
	<uni-popup ref="popup">
		<view class="popup-content">
			<uni-forms ref="valiForm" :rules="rules" :modelValue="formData" label-width="50">
				<uni-forms-item label="发票抬头" required name="header">
					<uni-easyinput v-model="formData.header" placeholder="请输入姓名" />
				</uni-forms-item>
				<uni-forms-item label="联系方式" required name="tel">
					<uni-easyinput v-model="formData.tel" placeholder="请输入电话" />
				</uni-forms-item>
			</uni-forms>
			<view class="btn" @click="submit">
				确定
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					header: '',
					tel: '',
					type:'person'
				},
				// 校验规则
				rules: {
					header: {
						rules: [{
							required: true,
							errorMessage: '请输入姓名'
						}]
					},
					tel: {
						rules: [{
							required: true,
							errorMessage: '请输入电话'
						}]
					},
				}
			}
		},
		props: {
			orderId: {
				default: ''
			},
		},
		methods: {
			open() {
				this.$refs.popup.open()
			},
			close() {
				this.$refs.popup.close()
			},
			submit() {
							this.$refs.valiForm.validate().then(res => {
								// console.log('success', res);
								if(!res.header)
								{
									uni.showToast({
										title:'请输入姓名',
										icon:'none'
									})
									return false
								}
								if(!res.tel)
								{
									uni.showToast({
										title:'请输入联系方式',
										icon:'none'
									})
									return false
								}
								this.formData.orderId = this.orderId
								this.$post(`/order/orderInvoice`, this.formData).then(res => {
										if(res.code === 200)
										{
											this.$toast("提交申请成功")
										}else{
											this.$toast(res.msg)
										}
										
										this.close()
									})
								
								
							
							}).catch(err => {
								console.log('err', err);
							})
						},
		}
	}
</script>

<style lang="scss">
	.popup-content {
		background-color: #fff;
		padding: 60rpx;
		border-radius: 30rpx;
		width: 90vw;

		.text {
			font-weight: bold;
			font-size: 56rpx;
		}

		.btn {
			margin: 0 auto;
			margin-top: 80rpx;
			width: 250rpx;
			line-height: 90rpx;
			border-radius: 25px;
			background-color: $assist-color2;
			// color: #fff;
			border: 2rpx solid #A4ADB3;
			font-size: 36rpx;
			text-align: center;
		}
	}
</style>